package com.cykj.user.controller;

import com.cykj.common.dto.ResponseDTO;
import com.cykj.user.service.IUserService;
import com.cykj.user.service.impl.EmailService;
import com.cykj.user.vo.CareerExpectVO;
import com.cykj.user.vo.RecruitInfoVO;
import com.cykj.user.vo.UserVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @BelongsProject: smart_recruit_backend
 * @BelongsPackage: com.cykj.user.controller
 * @Author: 浮行
 * @CreateTime: 2025-08-16 09:53
 * @Description: TODO
 * @Version: 1.0
 */
@RestController
@RequestMapping("/user")
@Tag(name = "用户端接口")
public class UserController {

    @Autowired
    private IUserService userService;
    @Autowired
    private EmailService emailService;

    //修改用户密码
    @PutMapping("/updatePassword")
    @Operation(summary = "修改用户密码")
    public ResponseDTO updatePassword(@RequestBody UserVO userVO){
         return userService.updatePassword(userVO);
    }
    //用户注册
    @RequestMapping("/enroll")
    public ResponseDTO enroll(){
        return null;
    }
    //修改用户姓名,电话号码,年龄信息
    @PutMapping("/update")
    @Operation(summary = "修改用户姓名,电话号码,年龄信息")
    public ResponseDTO update(@RequestBody UserVO userVO){
        return userService.update(userVO);
    }

    @Operation(summary = "用户登录-账号密码")
    @Parameters({
            @Parameter(name = "account",description = "账号",required = true,in = ParameterIn.HEADER),
            @Parameter(name = "password",description = "密码",required = true,in = ParameterIn.HEADER),
    })
    @PostMapping("/login")
    public ResponseDTO login(@RequestBody UserVO userVO){
        return userService.login(userVO);
    }

    @Operation(summary = "通过Id获取用户信息")
    @Parameters({
            @Parameter(name = "userId",description = "用户id",required = true,in = ParameterIn.QUERY)
    })
    @GetMapping("/getEphemeralData")
    public ResponseDTO getEphemeralData(@RequestParam("token")String token){
        return userService.getEphemeralData(token);
    }

    @Operation(summary = "获取职位类型,省级地区与行业的列表,用于筛选")
    @Parameters()
    @GetMapping("/getPositionTypeAndFirst")
    public ResponseDTO getPositionTypeAndFirst(){
        return userService.getPositionTypeAndFirst();
    }

    @Operation(summary = "通过职业类型Id获取该类型下的职业列表")
    @Parameters({
            @Parameter(name = "jobTypeId",description = "职业类型Id",required = true,in = ParameterIn.QUERY)
    })
    @GetMapping("/getJobsByTypeId")
    public ResponseDTO getJobsByTypeId(@RequestParam("jobTypeId") Integer jobTypeId){
        return userService.getJobsByTypeId(jobTypeId);
    }

    @Operation(summary = "通过省份Id获取市县列表")
    @Parameters({
            @Parameter(name = "ProvinceId",description = "省份Id",required = true,in = ParameterIn.QUERY)
    })
    @GetMapping("/getCountiesByProvinceId")
    public ResponseDTO getCountiesByProvinceId(@RequestParam("ProvinceId") Integer ProvinceId){
        return userService.getCountiesByProvinceId(ProvinceId);
    }

    @Operation(summary = "并新增期望职业,并补填个人信息")
    @Parameters({
            @Parameter(name = "userId",description = "用户Id",required = true,in = ParameterIn.HEADER),
            @Parameter(name = "payMethod",description = "薪资支付方式",required = true,in = ParameterIn.HEADER),
            @Parameter(name = "startSalary",description = "起始薪资",required = true,in = ParameterIn.HEADER),
            @Parameter(name = "maxSalary",description = "最终薪资",required = true,in = ParameterIn.HEADER),
            @Parameter(name = "industryId",description = "行业Id",required = true,in = ParameterIn.HEADER),
            @Parameter(name = "jobId",description = "期望职业Id",required = true,in = ParameterIn.HEADER),
            @Parameter(name = "regionId",description = "期望工作地点Id",required = true,in = ParameterIn.HEADER),
            @Parameter(name = "ProvinceId",description = "期望工作省份Id",required = true,in = ParameterIn.HEADER),
            @Parameter(name = "username",description = "用户名字",required = true,in = ParameterIn.HEADER),
            @Parameter(name = "age",description = "用户年龄",required = true,in = ParameterIn.HEADER),
            @Parameter(name = "gender",description = "用户性别",required = true,in = ParameterIn.HEADER),
            @Parameter(name = "jobSearchStatus",description = "用户求职状态",required = true,in = ParameterIn.HEADER),
            @Parameter(name = "degree",description = "用户学历",required = true,in = ParameterIn.HEADER)
    })
    @PutMapping("/submitCareerExpectInfo")
    public ResponseDTO submitCareerExpectInfo(@RequestBody CareerExpectVO careerExpectVO){
        return userService.submitCareerExpectInfo(careerExpectVO);
    }

    @Operation(summary = "发送电子邮箱验证码")
    @Parameters({
            @Parameter(name = "email",description = "电子邮箱",required = true,in = ParameterIn.QUERY)
    })
    @GetMapping("/sendEmailForVer")
    public ResponseDTO sendEmailForVer(@RequestParam("email")String email){
        System.out.println(email);
        return emailService.sendCaptchaEmail(email);
    }

    @Operation(summary = "注册用户")
    @Parameters({
            @Parameter(name = "email",description = "电子邮箱",required = true,in = ParameterIn.HEADER),
            @Parameter(name = "account",description = "账号",required = true,in = ParameterIn.HEADER),
            @Parameter(name = "password",description = "密码",required = true,in = ParameterIn.HEADER)
    })
    @PostMapping("/submitUserInfo")
    public ResponseDTO submitUserInfo(@RequestBody UserVO userVO){
        return userService.submitUserInfo(userVO);
    }

    @Operation(summary = "通过用户Id获取该用户的所有求职期望")
    @Parameters({
            @Parameter(name = "userId",description = "用户Id",required = true,in = ParameterIn.QUERY),
    })
    @GetMapping("/getCareerExpectByUserId")
    public ResponseDTO getCareerExpectByUserId(@RequestParam("userId") Integer userId){
        return userService.getCareerExpectByUserId(userId);
    }

    @Operation(summary = "通过地区Id获取该地区的名字与父级名字")
    @Parameters({
            @Parameter(name = "regionId",description = "地区Id",required = true,in = ParameterIn.QUERY),
    })
    @GetMapping("/getRegion")
    public ResponseDTO getRegion(@RequestParam("regionId") Integer regionId){
        return userService.getRegion(regionId);
    }

    @Operation(summary = "通过筛选获取符合用户需求的招聘信息")
    @Parameters({
            @Parameter(name = "regionId",description = "地区Id",required = false,in = ParameterIn.HEADER),
            @Parameter(name = "jobId",description = "职位Id",required = false,in = ParameterIn.HEADER),
            @Parameter(name = "payMethod",description = "薪资支付方式",required = false,in = ParameterIn.HEADER),
            @Parameter(name = "startSalary",description = "起始薪资",required = false,in = ParameterIn.HEADER),
            @Parameter(name = "maxSalary",description = "最高薪资",required = false,in = ParameterIn.HEADER),
            @Parameter(name = "companyType",description = "公司资质",required = false,in = ParameterIn.HEADER),
            @Parameter(name = "industryId",description = "行业Id",required = false,in = ParameterIn.HEADER),
            @Parameter(name = "companySize",description = "公司规模",required = false,in = ParameterIn.HEADER),
            @Parameter(name = "pageNum",description = "当前页数",required = true,in = ParameterIn.QUERY),
            @Parameter(name = "pageSize",description = "每页条数",required = true,in = ParameterIn.QUERY),
    })
    @PostMapping("/recommendedRecruit")
    public ResponseDTO recommendedRecruit(@RequestBody RecruitInfoVO recruitInfoVO,@RequestParam("pageNum")Integer pageNum,@RequestParam("pageSize")Integer pageSize){
        return userService.recommendedRecruit(recruitInfoVO,pageNum,pageSize);
    }

    @Operation(summary = "通过期望Id删除对应期望")
    @Parameters({
            @Parameter(name = "expectId",description = "期望Id",required = true,in = ParameterIn.PATH),
    })
    @DeleteMapping("/deleteCareerExpect/{expectId}")
    public ResponseDTO deleteCareerExpect(@PathVariable("expectId") Integer expectId){
        return userService.deleteCareerExpect(expectId);
    }

    @Operation(summary = "添加求职期望")
    @Parameters({
            @Parameter(name = "startSalary",description = "起始薪资",required = false,in = ParameterIn.HEADER),
            @Parameter(name = "maxSalary",description = "最终薪资",required = false,in = ParameterIn.HEADER),
            @Parameter(name = "userId",description = "用户Id",required = true,in = ParameterIn.HEADER),
            @Parameter(name = "payMethod",description = "支付方式",required = true,in = ParameterIn.HEADER),
            @Parameter(name = "industryId",description = "行业Id",required = true,in = ParameterIn.HEADER),
            @Parameter(name = "jobId",description = "职位Id",required = true,in = ParameterIn.HEADER),
    })
    @PutMapping("/addCareerExpect")
    public ResponseDTO addCareerExpect(@RequestBody CareerExpectVO careerExpectVO){
        return userService.addCareerExpect(careerExpectVO);
    }

    @Operation(summary = "修改求职期望的地区")
    @Parameters({
            @Parameter(name = "expectId",description = "期望Id",required = true,in = ParameterIn.HEADER),
            @Parameter(name = "regionId",description = "地区Id",required = true,in = ParameterIn.HEADER),
    })
    @PostMapping("/updateCareerExpectationRegion")
    public ResponseDTO updateCareerExpectationRegion(@RequestBody CareerExpectVO careerExpectVO){
        return userService.updateCareerExpectationRegion(careerExpectVO);
    }

    @Operation(summary = "修改求职期望的地区为空")
    @Parameters({
            @Parameter(name = "expectId",description = "期望Id",required = true,in = ParameterIn.HEADER),
    })
    @PostMapping("/updateCareerExpectationRegionIsNull")
    public ResponseDTO updateCareerExpectationRegionIsNull(@RequestBody CareerExpectVO careerExpectVO){
        return userService.updateCareerExpectationRegionIsNull(careerExpectVO);
    }

    @Operation(summary = "获取招聘与对应的信息")
    @Parameters({
            @Parameter(name = "recruitId",description = "招聘信息Id",required = true,in = ParameterIn.QUERY),
            @Parameter(name = "userId",description = "用户Id",required = true,in = ParameterIn.QUERY),
    })
    @GetMapping("/getRecruitAndElse")
    public ResponseDTO getRecruitAndElse(@RequestParam("recruitId")Integer recruitId,@RequestParam("userId")Integer userId){
        return userService.getRecruitAndElse(recruitId,userId);
    }

    @Operation(summary = "获取公司信息")
    @Parameters({
            @Parameter(name = "companyId",description = "公司Id",required = true,in = ParameterIn.QUERY),
    })
    @GetMapping("/getCompanyInfoByCompanyId")
    public ResponseDTO getCompanyInfoByCompanyId(@RequestParam("companyId")Integer companyId){
        return userService.getCompanyInfoByCompanyId(companyId);
    }

    @Operation(summary = "获取搜索的招聘信息信息")
    @Parameters({
            @Parameter(name = "searchKeyword",description = "搜索关键词",required = true,in = ParameterIn.QUERY),
            @Parameter(name = "pageNum",description = "当前页数",required = true,in = ParameterIn.QUERY),
            @Parameter(name = "pageSize",description = "每页条数",required = true,in = ParameterIn.QUERY),
    })
    @GetMapping("/search")
    public ResponseDTO search(@RequestParam("searchKeyword")String searchKeyword,@RequestParam("pageNum")Integer pageNum,@RequestParam("pageSize")Integer pageSize){
        return userService.search(searchKeyword,pageNum,pageSize);
    }


    @Operation(summary = "获取用户的预约信息")
    @Parameters({
            @Parameter(name = "userId",description = "用户Id",required = true,in = ParameterIn.QUERY),
    })
    @GetMapping("/getInterview")
    public ResponseDTO getInterview(@RequestParam("userId")Integer userId){
        return userService.getInterview(userId);
    }

    @Operation(summary = "获取预约的详细信息")
    @Parameters({
            @Parameter(name = "bookingId",description = "预约Id",required = true,in = ParameterIn.QUERY),
    })
    @GetMapping("/getInterviewDeta")
    public ResponseDTO getInterviewDeta(@RequestParam("bookingId")Integer bookingId){
        return userService.getInterviewDeta(bookingId);
    }

    @Operation(summary = "查询用户订单")
    @Parameters({
            @Parameter(name = "userId",description = "用户Id",required = true,in = ParameterIn.QUERY),
    })
    @GetMapping("/getOrderByUserId")
    public ResponseDTO getOrderByUserId(@RequestParam("userId")Integer userId){
        return userService.getOrderByUserId(userId);
    }

    @Operation(summary = "查询订单详细信息")
    @Parameters({
            @Parameter(name = "orderId",description = "订单Id",required = true,in = ParameterIn.QUERY),
    })
    @GetMapping("/getOrderInfo")
    public ResponseDTO getOrderInfo(@RequestParam("orderId")Integer orderId){
        return userService.getOrderInfo(orderId);
    }

    @Operation(summary = "查询用户距离企业距离")
    @Parameters({
            @Parameter(name = "lat",description = "用户纬度",required = true,in = ParameterIn.QUERY),
            @Parameter(name = "lng",description = "用户经度",required = true,in = ParameterIn.QUERY),
            @Parameter(name = "companyId",description = "企业Id",required = true,in = ParameterIn.QUERY),
    })
    @GetMapping("/getJuLi")
    public ResponseDTO getJuLi(@RequestParam("lat")Double lat,@RequestParam("lng")Double lng,@RequestParam("companyId")Integer companyId){
        return userService.getJuLi(lat,lng,companyId);
    }

    @Operation(summary = "收藏与取消收藏招聘信息")
    @Parameters({
            @Parameter(name = "userId",description = "用户Id",required = true,in = ParameterIn.QUERY),
            @Parameter(name = "recruitId",description = "招聘Id",required = true,in = ParameterIn.QUERY),
            @Parameter(name = "isNo",description = "判断是不是删除收藏(0-是,1-不是)",required = true,in = ParameterIn.QUERY),
    })
    @GetMapping("/collectRecruit")
    public ResponseDTO collectRecruit(@RequestParam("userId")Integer userId,@RequestParam("recruitId")Integer recruitId,@RequestParam("isNo")Integer isNo){
        return userService.collectRecruit(userId,recruitId,isNo);
    }


}
